package clue

import (
	"git.mycaigou.com/gfyx/micro-gfyx-mp-api/http_server/controller"
	reportDto "git.mycaigou.com/gfyx/micro-gfyx-mp-api/http_server/dto/report"
	"git.mycaigou.com/gfyx/micro-gfyx-mp-api/infrastructure/common/errcode"
	"git.mycaigou.com/gfyx/micro-gfyx-mp-api/service/business_opportunity/common"
	"git.mycaigou.com/gfyx/micro-gfyx-mp-api/service/clue/report"
	"git.myscrm.cn/golang/stark/v4"
	"github.com/gin-gonic/gin"
)

type AnonymityController struct {
	controller.BaseController
	reportService report.ReportServiceIface
	commonService common.CommonServiceIface
}

// NewAnonymityController
// 构造函数
func NewAnonymityController(reportService report.ReportServiceIface,
	commonService common.CommonServiceIface,
) *AnonymityController {
	return &AnonymityController{
		reportService: reportService,
		commonService: commonService,
	}
}

// RegisterRouter
// 注册路由
func (c *AnonymityController) RegisterRouter(g *gin.RouterGroup) {
	// 报备列表
	g.POST("/report-info", c.ReportInfo)
}

func (c *AnonymityController) ReportInfo(ctx *gin.Context) {
	// 临时记录gin的请求
	request := &reportDto.ReportInfoRequestDto{}
	if err := ctx.ShouldBind(request); err != nil {
		stark.Logger.Errorf(ctx, "错误code:", errcode.COMMON_PARAMS_ERROR, ",错误msg:,", err)
		c.Fail(ctx, errcode.COMMON_PARAMS_ERROR, "参数异常")
		return
	}

	reportInfo, err := c.reportService.ReportInfo(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "ReportInfo-error: %+v, CODE: %s", err.Error(), request.Code)
		c.Fail(ctx, errcode.COMMON_DATA_NOT_EXIST, err.Error())
		return
	}

	c.Success(ctx, reportInfo)
}
